const Router = require('koa-router')
const { auth } = require('../middle/auth')
const router = new Router({
  prefix: '/questions/:questionId/answer'
})

const {checkAnswerExist, checkAnswerOwner, createAnswer, seachAnswer, getAnswer, updateAnswer, deleteAnswer } = require('../controllers/answer')

router.get('/', seachAnswer)  // 搜索/获取回答
router.get('/:answerId', checkAnswerExist, getAnswer)  // 获取特定答案
router.post('/',auth, createAnswer) // 创建回答
router.patch('/:answerId', auth, checkAnswerExist, checkAnswerOwner, updateAnswer) // 更新回答
router.delete('/:answerId',auth, checkAnswerExist, checkAnswerOwner,deleteAnswer) // 删除回答

module.exports = router